/*
 * @Author: xinyang3
 * @Date: 2021-07-27 09:36
 * @Descripttion: function
 * @LastEditors: xinyang3
 * @LastEditTime: 2021-07-27 11:41
 */

// optional and default parameters
type Context = {
  appId?: string;
  userId?: string;
};

// 方法参数自定义类型和默认值
function log(message: string, context: Context = {}): void {
  let time = new Date().toLocaleDateString();
  console.log(time);
}

// rest parameters
// 可变参数注解 array => arguments
interface Console {
  log(message: any, optionalParams: any[]): void;
}

function sumVariadic(): number {
  return Array.from(arguments).reduce((total, n) => total + n, 0);
}

// call type
// 函数类型语法 alias
type Greet = (name: string) => string;
type Log = (message: string, userId?: string) => void;
type SumVariadic = (...numbers: number[]) => number;

// 从新定义log
let log2: Log = (message, userId = 'xinyang3') => {
  let time = new Date().toLocaleDateString();
  console.log(time);
};
